#include<iostream>

using namespace std;

#include "player.h"
#include "Territory.h"

Player::Player(QString color, QString name) :
        m_num_armies(0),
        m_name(name),
        m_ColorString(color)
{
    if(color == "Red")
        m_color = RED;
    else if(color == "Orange")
        m_color = ORANGE;
    else if(color == "Yellow")
        m_color = YELLOW;
    else if(color == "Green")
        m_color = GREEN;
    else if(color == "Blue")
        m_color = BLUE;
    else if(color == "Purple")
        m_color = PURPLE;
}

Player::~Player()
{
    for(unsigned int n = 0;n < m_territories.size();++n)
    {
        m_territories[n] = NULL;
    }
    for(unsigned int n = 0;n < m_cards.size();++n)
    {
        m_cards[n] = NULL;
    }
}

void Player::addTerritory(Territory* toAdd)
{
    m_territories.push_back(toAdd);
}

void Player::removeTerritory(Territory* toRemove)
{
    // The vector::erase method doesn't take an index -- it takes an "iterator"
    // this loop construct can be used instead to iterate across the vector
    // and remove the matching element. --CDP
    for (vector<Territory*>::iterator it = m_territories.begin();
         *it != (*m_territories.end());
         ++it)
    {
        if(*it == toRemove)
        {
            m_territories.erase(it);
            return;
        }
    }
}

int Player::getNumTerr()
{
    return m_territories.size();
}

void Player::addCard(Cards* toAdd)
{
    m_cards.push_back(toAdd);
}
